package netw;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

public class wad {
	
	class SyncPipe implements Runnable
	{
	public SyncPipe(InputStream istrm, OutputStream ostrm) {
	      istrm_ = istrm;
	      ostrm_ = ostrm;
	  }
	  public void run() {
	      try
	      {
	          final byte[] buffer = new byte[1024];
	          for (int length = 0; (length = istrm_.read(buffer)) != -1; )
	          {
	              ostrm_.write(buffer, 0, length);
	          }
	      }
	      catch (Exception e)
	      {
	          e.printStackTrace();
	      }
	  }
	  private final OutputStream ostrm_;
	  private final InputStream istrm_;
	}
	
	public wad() throws IOException{
	String[] command =
	    {
	        "cmd",
	    };
	    Process p = Runtime.getRuntime().exec(command);
	    new Thread(new SyncPipe(p.getErrorStream(), System.err)).start();
	    new Thread(new SyncPipe(p.getInputStream(), System.out)).start();
	    PrintWriter stdin = new PrintWriter(p.getOutputStream());
	    
	    stdin.println("netsh wlan set hostednetwork mode=allow ssid=LocalAdHoc key=password");
	    stdin.println("netsh wlan start hostednetwork");
	    //String a =String.valueOf((int)(Math.random()*254)+1);
	    //String b =String.valueOf((int)(Math.random()*254)+1);
	    //String c =String.valueOf((int)(Math.random()*254)+1);
	    stdin.println("netsh int ip set address \"local area connection 2\" static 192."+"a"+"."+"b"+"."+"c"+" 255.255.255.0 192.168.0.254 1");
	    stdin.close();
	    int returnCode = 0;
		try {
			returnCode = p.waitFor();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	    System.out.println("Return code = " + returnCode);	
	}
	public static void main( String[] args ) throws IOException{
		new wad();
	}
	

}
